package Control;

import java.util.LinkedList;

import DBHandler.Searcher;
import DBHandler.SearcherObserver;

public class SearchEx implements SearcherObserver{
	
	
	Searcher searcher;
	LinkedList<SearchExObserver> observer_list;
	
	
	
	public SearchEx(Searcher searcher) {
		this.searcher = searcher;
		
	}
	
	
	//this method will be called from a listener in search win (gui)
	public void search (String str)
	{
		System.out.println("searchEx passing search string");
		searcher.search(str);
	}
	
	
	
	public void addObserver(SearchExObserver ex_observer)
	{
		if (observer_list == null)
			observer_list = new LinkedList<SearchExObserver>();
		
		observer_list.add(ex_observer);
		//pass the subject 'role' to 'Searcher'
		searcher.addObserver(this);
	}
	
	
	//will notify the gui for update (a search result basically)
	@Override
	public void update() {

		for(SearchExObserver o: observer_list)
		{
			o.update();
		}
	}
	
	
	//when the user selects a file from gui, this will be called and changes the 'current' file for 'searcher'
	public void selectFile(String name)
	{
		searcher.selectFile(name);
	}
	
	
	

}
